<?php
class Cms_Model_DAO_Subscriber
{    
	private $_db;
	private static $_instance = null;
	private static $_table = "subscriber";
 
	/**
	 * @return Cms_Model_DAO_Subscriber
	 * */
	public static function factory() {
		if(self::$_instance == null) {
			self::$_instance = new self();
		}
		
		return self::$_instance;
	}
	
    private function __construct()
    {
    	$module = Utils_Global::get('module');
		$this->_db = Utils_Global::getDbInstance($module);
    }
	
	/**
	 * Insert new subscriber
	 * @param array $data user information
	 * @return array
	 * */
	public function insert($data) {
	    $this->_db->insert(self::$_table, $data);
	    $result = $this->_db->lastInsertId();
	    return $result;
	}
	
	/**
	 * Update subscribe info
	 * @param string email
	 * @param array $data update info
	 * @return boolean true on success, otherwise false
	 * */
	public function update($email, $data) {
	    $result = $this->_db->update(self::$_table, $data, "email={$this->_db->quote($email)}");
	    return $result;
	}
}